package com.zzw.hj67;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 24点游戏
 * @Author: zzw
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int[] nums = new int[4];
            for (int i = 0; i < 4; i++) {
                nums[i] = in.nextInt();
            }

            // 加减乘除 运算结果24
            // 四个运算符 + 不同运算顺序
            boolean ans = dfs(nums, new int[4], 0, 0);
            System.out.println(ans);
        }
    }

    public static boolean dfs(int[] nums, int[] judge, double count,
                              int index) { // judge防止元素重复利用
        // 终止条件
        if (count == 24.0)
            return true;
        else if (index == 4)
            return false;

        if (index == 0) { // 获取第一个数
            for (int i = 0; i < 4; i++) {
                judge[i] = 1;
                if (dfs(nums, judge, count + nums[i], index + 1)) {
                    return true;
                }
                judge[i] = 0;
            }
        } else { // 非第一个数的情况
            for (int i = 0; i < 4; i++) {
                if (judge[i] == 0) {
                    judge[i] = 1;
                    // 加法
                    if (dfs(nums, judge, count + nums[i], index + 1))
                        return true;
                    // 减法
                    if (dfs(nums, judge, count - nums[i], index + 1))
                        return true;
                    // 乘法
                    if (dfs(nums, judge, count * nums[i], index + 1))
                        return true;
                    // 除法
                    if (dfs(nums, judge, count / nums[i], index + 1))
                        return true;
                    judge[i] = 0;
                }
            }
        }

        return false;
    }
}